package org.blame;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class JedisDemoHash {
    public static void main(String[] args) {
        JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis=jedisPool.getResource()){
//            test1(jedis);
//            test2(jedis);
//            test3(jedis);
//            test4(jedis);
            test5(jedis);
        }
    }

    public static void test5(Jedis jedis){
        jedis.flushAll();
        jedis.hset("k","f1","111");
        jedis.hset("k","f2","111");
        jedis.hset("k","f3","111");
        jedis.hset("k","f4","111");

        List<String> hmget = jedis.hmget("k", "f1", "f2", "f3");
        System.out.println(hmget);



    }
    public static void test4(Jedis jedis){
        jedis.flushAll();
        jedis.hset("k","f1","111");
        jedis.hset("k","f2","111");
        jedis.hset("k","f3","111");
        jedis.hset("k","f4","111");
        List<String> k1 = jedis.hvals("k");
        Set<String> k = jedis.hkeys("k");
        System.out.println(k1);
        System.out.println(k);


    }
    public static void test3(Jedis jedis){
        jedis.flushAll();
        jedis.hset("k","f1","111");
        jedis.hset("k","f2","111");
        jedis.hset("k","f3","111");
        jedis.hset("k","f4","111");
        long hdel = jedis.hdel("k", "f1", "f2", "f4");
        System.out.println(hdel);
        boolean hexists = jedis.hexists("k", "f1");
        System.out.println(hexists);


    }
    public static void test2(Jedis jedis){
        jedis.flushAll();
        jedis.hset("k","f1","111");
        boolean hexists = jedis.hexists("k", "f1");
        System.out.println(hexists);
        boolean hexists1 = jedis.hexists("k", "f2");
        System.out.println(hexists1);
    }

        public static void test1(Jedis jedis){
        jedis.flushAll();
        jedis.hset("k","f1","111");
        Map<String,String> hashMap=new HashMap<>();
        hashMap.put("f2","12");
        hashMap.put("f3","13");
        hashMap.put("f4","14");
        hashMap.put("f5","15");
        jedis.hset("k",hashMap);
        String hget = jedis.hget("k", "f1");
        System.out.println(hget);
        hget = jedis.hget("k", "f2");
        System.out.println(hget);
        hget = jedis.hget("k", "f3");
        System.out.println(hget);
        hget = jedis.hget("k", "f4");
        System.out.println(hget);

    }
}
